package com.ineatconseil.yougo.components.models;

import java.util.ArrayList;
import java.util.List;

import org.apache.tapestry5.OptionGroupModel;
import org.apache.tapestry5.OptionModel;
import org.apache.tapestry5.internal.OptionModelImpl;
import org.apache.tapestry5.util.AbstractSelectModel;

import com.ineatconseil.yougo.dto.RequestTypeDto;
import com.ineatconseil.yougo.exceptions.RestServiceException;
import com.ineatconseil.yougo.services.rest.RestPath;
import com.ineatconseil.yougo.services.rest.RestServiceInvoker;
import com.sun.jersey.api.client.GenericType;

/**
 * Component use to generate a combobox for "Request types".
 * 
 * @author johanblo
 * 
 */
public class RequestTypeSelectModel extends AbstractSelectModel {

	/**
	 * The options values.
	 */
	private List<OptionModel> options = new ArrayList<OptionModel>();

	public RequestTypeSelectModel(RestServiceInvoker invoker) {

		try {

			List<RequestTypeDto> types =
					invoker.call(RestPath.getSimplePath(RestPath.PATH_REQUEST_TYPES, ""),
							new GenericType<List<RequestTypeDto>>() {
							});

			// Mapp :
			for (RequestTypeDto currentReq : types) {
				this.options.add(new OptionModelImpl(currentReq.getDescription(), currentReq.getId()));
			}

		} catch (RestServiceException e) {

		}

	}

	public List<OptionGroupModel> getOptionGroups() {
		return null;
	}

	public List<OptionModel> getOptions() {
		return this.options;
	}
}